package com.xiaocikuai.smallchunks.utils;


import com.xiaocikuai.smallchunks.mapper.User.UserMapper;
import jakarta.annotation.Resource;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
public class ExcelUtil {

    @Resource
    private UserMapper userMapper;


    public boolean getExcel(){
        List<String> productList = new ArrayList<>();
        productList.add("昵称");
        List<String> strings = userMapper.getNickname();
        productList.addAll(strings);

        // 价格列表
        List<String> priceList = new ArrayList<>();
        priceList.add("兑换码");
        List<String> stringss = userMapper.getCode(strings.size());
        priceList.addAll(stringss);


                // 创建工作簿
        Workbook workbook = new XSSFWorkbook();

        // 创建工作表
        Sheet sheet = workbook.createSheet("Sheet1");

        // 标题样式
        CellStyle headerStyle = workbook.createCellStyle();
        Font headerFont = workbook.createFont();
        headerFont.setBold(true);
        headerStyle.setFont(headerFont);

        int rowNum = 0;
        for (int i = 0; i < productList.size(); i++) {
            Row row = sheet.createRow(rowNum++);
            Cell productCell = row.createCell(0);
            if (rowNum == 1) {
                productCell.setCellStyle(headerStyle);
            }
            productCell.setCellValue(productList.get(i));

            Cell priceCell = row.createCell(1);
            if (rowNum == 1) {
                priceCell.setCellStyle(headerStyle);
            }
            priceCell.setCellValue(priceList.get(i));
        }

        // 保存文件
        try (FileOutputStream outputStream = new FileOutputStream("")) {
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return  true;
    }

//    public void ggggggggggg(){
//        FileInputStream fis = new FileInputStream(filePath);
//        Workbook workbook = new XSSFWorkbook(fis)) {
//            Sheet sheet = workbook.getSheetAt(0);  // 假设读取第一个工作表
//            for (Row row : sheet) {
//
//                Cell cell1 = row.getCell(column1);
//                Cell cell2 = row.getCell(column2);
//
//
//            }
//
//            // 打印第一列数据
//            System.out.println("第一列数据:");
//            for (String data : column1Data) {
//                System.out.println(data);
//            }
//
//            // 打印第二列数据
//            System.out.println("第二列数据:");
//            for (String data : column2Data) {
//                System.out.println(data);
//            }
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//
//    }



}
